package com.cmccgz.udacs_landlord_webapp.main.housemanager.function;

import com.cmccgz.udacs_landlord_webapp.bean.HousePeopleBean;
import com.cmccgz.udacs_landlord_webapp.bean.MobileBean;
import com.cmccgz.udacs_landlord_webapp.data.BaseCallback;
import com.cmccgz.udacs_landlord_webapp.data.HouseManagerDataSource;
import com.cmccgz.udacs_landlord_webapp.data.HouseManagerRepository;

import java.util.List;

/**
 * @author: Huang
 * @Descripion:
 * @date 2017/6/2 16:47
 */

public class HouseCheckOutPresenter implements HouseFunctionContract.CheckOutPresenter {

    private HouseFunctionContract.CheckOutView mView;
    private HouseManagerRepository mRepository;

    public HouseCheckOutPresenter(HouseManagerRepository houseManagerRepository, HouseFunctionContract.CheckOutView fragment) {
        this.mRepository = houseManagerRepository;
        this.mView = fragment;
        this.mView.setPresenter(this);
    }

    @Override
    public void start() {
    }

    @Override
    public void getDetail(String houseId) {
        if (mView.isActive()) {
            mRepository.getHouseDetail(houseId, new HouseManagerDataSource.HouseDetailCallback() {
                @Override
                public void onHouseDetailLoaded(List<HousePeopleBean> list) {
                    mView.getDataSuccess(list);
                }

                @Override
                public void onLoadedFailed(String msg) {
                    mView.getDataFailed(msg);
                }
            });
        }
    }

    @Override
    public void commit(List<MobileBean> bean, String houseId) {
        if (mView.isActive()) {
            mRepository.checkout(bean, houseId, new BaseCallback() {
                @Override
                public void onSuccess() {
                    mView.commitSuccess();
                }

                @Override
                public void onFailed(String msg) {
                    mView.commitFailed(msg);
                }
            });
        }
    }
}
